<admintpl file="header"/>
</head>
<body>
<style>
    .radio {
        margin-top: 5px;
        margin-left: 15px;
        float: left;
    }
    ul, ol {
        list-style: none outside none;
    }
    em.zt {
        font-size: 0;
        line-height: 0;
        width: 0;
        height: 0;
        display: inline-block;
        padding: 0;
        border: 4px solid;
        border-color: #333 transparent transparent transparent;
        border-style: solid dashed dashed dashed;
    }
    .ks-stdmod-body label {
        display: inline-block;
    }
    #calroot {
        z-index: 1000;
    }
</style>
<link rel="stylesheet" href="__TMPL__Public/assets/css/transport.css"/>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:U('Materials/index')}">物料管理</a></li>
        <li><a href="{:U('Materials/add')}">添加物料</a></li>
        <li class="active"><a href="{:U('Materials/edit', array('id'=>$card['id']))}" target="_self">编辑物料</a></li>
        <li><a href="{:U('Materials/real')}" >卡券列表</a></li>
    </ul>
        <form action="{:U('Materials/edit_materials')}" method="post" class="form-horizontal js-ajax-form" enctype="multipart/form-data">
        <div class="row-fluid">
            <div class="span9">
                    <table class="table table-bordered">
                        <input type="text"  name="id" value="{$card.id}" class="hide"/>
                        <input type="text"  name="huodong_extend_id" value="{$card_huodong.id}" class="hide"/>
                        <input type="text"  name="card_detail_id" value="{$card_detail.id}" class="hide"/>
                    <tr>
                        <th width="80px">名称</th>
                        <td>
                            <input type="text" name="card_name" id="title" required value="{$card.card_name}" placeholder="请输入名称" maxlength="16"/>最长16个汉字、不可为空
                        </td>
                    </tr>
                    <tr>
                        <th>投放类型</th>
                        <td>
                        <input type="hidden" name="card_type" value="{$card.card_type}" />
				          	<span class="switch_list cc">
				        		<foreach name="cardTypeList" item="vo">
                                    <label class="radio">
										<input type="radio" value="{$vo.id}" <if condition="$card['card_type'] eq $vo['id']" >checked</if>  disabled>
                                        <span>{$vo.name}</span>
                                    </label>
				                </foreach>
							</span>
                        </td>
                    </tr>
                   <!-- <tr>
                        <th id="prizes_grade">奖品级别 <br> (选填)</th>
                        <td>
                            <select name="prizes_grade">
                                <option value="">请选择</option>
                                <foreach name="prizesGradeList" item="vo"  >
                                    <option value="{$vo.id}" <if condition="$card_huodong['prizes_grade'] eq $vo['id']" >selected</if>>{$vo.name}</option>
                                </foreach>
                            </select>
                        </td>
                    </tr>-->
                    <tr>
                        <th id="card_count_th">卡券总量/个</th>
                        <td>
                            <input type="text" value="{$card.card_count}" readonly>最大6位数、不可为空
                        </td>
                    </tr>
                    <tr id="card_detail" style="display:none">
                        <th>核销密码</th>
                        <td>
                            <input type="text" value="{$card.password}" readonly>最大6位数、不可为空
                        </td>
                    </tr>
                    <tr class='card_detail' style="display:none">
                        <th>每券价值抱抱币/个</th>
                        <td>
                            <input type="text" value="{$card.worth}"  readonly>最大6位数、不可为空
                        </td>
                    </tr>
                    <tr id="redinput" style="display:none">
                        <th>中奖金额/分</th>
                        <td>
                            <input type="text" name="min_money" required style="width: 88px;" placeholder="最小值" value="{$card.min_money}" maxlength="4" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"> ~
                            <input type="text" name="max_money" required style="width: 88px;" placeholder="最大值" value="{$card.max_money}" maxlength="8" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">最小值最大4位数、最大值最大8位数、均不可为空
                        </td>
                    </tr>
                    <tr>
                        <th>中奖限制</th>
                        <td>
                            <input type="text" name="day_count_limit_by_user" style="width: 88px;" required  value="{$card.day_count_limit_by_user}" maxlength="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">次/人/天
                            <input type="text" name="count_limit_by_user" style="width: 88px;" required  value="{$card.count_limit_by_user}" maxlength="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">次/人/总计
                            <input type="text" name="card_count_day" style="width: 88px;" required value="{$card.card_count_day}" maxlength="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">次/总计/天
                            <br>
                            最大10位数、空为不限制。
                        </td>
                    </tr>
                    <tr>
                        <th>开始日期</th>
                        <td>
                            <input type="text" name="start_at" class="js-datetime" autocomplete="off" value="{$card.start_at}">
                        </td>
                    </tr>
                    <tr>
                        <th>结束日期</th>
                        <td>
                            <input type="text" name="end_at" class="js-datetime" autocomplete="off" value="{$card.end_at}">
                        </td>
                    </tr>
                    <tr data-group="n1">
                        <th>投放筛选</th>
                        <td class="cell-area">
                            <a class="acc_popup edit J_EditArea" title="编辑运送区域" area-haspopup="true"
                               area-controls="J_DialogArea" entype="J_EditArea" data-acc="event:enter"
                               href="JavaScript:void(0);">地域投放</a>
                                <span class="area-group">
                                    <input class="J_BatchField" style="width:15px;display:none" type="checkbox" value="" name="es_n1">
                                    <p>{$card.areaNameList}</p>
                                </span>
                            <input type="hidden" value="{$card.bind_location}" name="areas[es][1]">
                        </td>
                    </tr>
                        <tr>
                            <th>选择群组<input type="checkbox" name="group" value="1" style="margin:0 2px 0;"<if condition="count($card_groups)"> checked </if>><br>(选填)</td>
                            <td>
                                <div id="groupbox" <if condition="!count($card_groups)"> style="display:none" </if>>
                                <foreach name="groups" item="vo">
                                    <label style="float: left; margin-right:10px;">
                                        <input type="checkbox" name="groups[]" value="{$vo.id}"
                                        <foreach name="card_groups" item="egroup">
                                            <if condition="$vo['id'] eq $egroup['area_id']">
                                                checked
                                            </if>
                                        </foreach>
                                        ><span>{$vo.name}</span>
                                    </label>
                                </foreach>
                                <div></div>
                                <foreach name="customGroups" item="vo">
                                    <label style="float: left; margin-right:10px;">
                                        <input type="checkbox" name="customGroups[]" value="{$vo.id}"
                                        <foreach name="card_customGroups" item="egroup">
                                            <if condition="$vo['id'] eq $egroup['area_id']">
                                                checked
                                            </if>
                                        </foreach>
                                        ><span>{$vo.area_name}</span>
                                    </label>
                                </foreach>
                                </div>
                            </td>
                        </tr>
                    <!--<tr>
                        <th>库存预警</th>
                        <td>
                            <input type="text" name="yj_num"style="width: 78px;" maxlength="4" placeholder="预警数/金额" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" value="{$card.yj_num}">
                            <input type="text" name="yj_phone" style="width: 110px;" maxlength="11" placeholder="通知手机号" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" value="{$card.yj_phone}">库存预警最长4位数字、手机号11位数字
                        </td>
                    </tr>-->
                    <tr>
                        <th>图片链接<br>(选填)</th>
                        <td>
                            <textarea name="card_url" maxlength="200" style="width: 70%;" rows=3 placeholder="请填写展示图片链接地址">{$card.card_url}</textarea>最长200位字符
                        </td>
                    </tr>
                    <tr>
                        <th>中奖词</th>
                        <td>
                            <input type="text" name="congratulations" maxlength="16" required style="width: 70%;"  placeholder="请填写中奖词" value="{$card.congratulations}"/>最长16个汉字
                        </td>
                    </tr>
                    <tr>
                        <th>简介</th>
                        <td>
                            <input type="text" name="card_intro" required style="width: 70%;" maxlength="40"  placeholder="请填写物料介绍" value={$card.card_intro}>
                            <br>卡券详情展示在用户中奖页面和卡券列表页面,最长16个汉字
                        </td>
                    </tr>
                    <tr  class='card_detail'>
                        <th>微信卡券号<br>(选填)</th>
                        <td>
                            <input type="text" name="wxcard" placeholder="请输入微信卡券id" maxlength="40" value={$card.external_cardid}>微信卡券ID,可从微信公共平台查看
                        </td>
                    </tr>
                    <tr class='card_detail'>
                        <th>有效期<br>(选填)</th>
                        <td>
                            <input type="text" name="card_sdate" class="js-date" autocomplete="off" placeholder="开始日期" value="{$card_detail.card_sdate}">
                            <input type="text" name="card_edate" class="js-date" autocomplete="off" placeholder="结束日期" value="{$card_detail.card_edate}">
                        </td>
                    </tr>
                    <tr class='card_detail'>
                        <th>可用时段<br>(选填)</th>
                        <td>
                            <div class="row">
                                <div class="span12 offset1">
                                <label class="radio">
                                    <input type="radio" name="open_time_type" id="optionsRadios1" value="1"  <if condition="$card_detail['open_time_type'] eq 1" >checked</if>>
                                    全部时段
                                </label>
                                <label class="radio">
                                    <input type="radio" name="open_time_type" id="optionsRadios2" value="2" <if condition="$card_detail['open_time_type'] eq 2" >checked</if>>
                                    部分时段
                                </label>
                                </div>
                                <div class="span12 offset1 open_time_area" style="display:none">
                                    <label class="checkbox inline">
                                        日期:
                                    </label>
                                    <label class="checkbox inline">
                                        <input type="checkbox" id="inlineCheckbox1" name="open_time_day[]" value="1"  style="margin-left: 0px" <if condition="in_array(1, $card_detail['open_time_day'])" >checked</if>> 星期一
                                    </label>
                                    <label class="checkbox inline">
                                        <input type="checkbox" id="inlineCheckbox2" name="open_time_day[]" value="2" style="margin-left: 0px" <if condition="in_array(2, $card_detail['open_time_day'])" >checked</if>> 星期二
                                    </label>
                                    <label class="checkbox inline">
                                        <input type="checkbox" id="inlineCheckbox3" name="open_time_day[]" value="3" style="margin-left: 0px" <if condition="in_array(3, $card_detail['open_time_day'])" >checked</if>> 星期三
                                    </label>
                                    <label class="checkbox inline">
                                        <input type="checkbox" id="inlineCheckbox4" name="open_time_day[]" value="4" style="margin-left: 0px" <if condition="in_array(4, $card_detail['open_time_day'])" >checked</if>> 星期四
                                    </label>
                                    <label class="checkbox inline">
                                        <input type="checkbox" id="inlineCheckbox5" name="open_time_day[]" value="5" style="margin-left: 0px" <if condition="in_array(5, $card_detail['open_time_day'])" >checked</if>> 星期五
                                    </label>
                                    <label class="checkbox inline">
                                        <input type="checkbox" id="inlineCheckbox6" name="open_time_day[]" value="6" style="margin-left: 0px" <if condition="in_array(6, $card_detail['open_time_day'])" >checked</if>> 星期六
                                    </label>
                                    <label class="checkbox inline">
                                        <input type="checkbox" id="inlineCheckbox7" name="open_time_day[]" value="0" style="margin-left: 0px" <if condition="in_array(0, $card_detail['open_time_day'])" >checked</if>> 星期日
                                    </label>
                                </div>
                                <div class="span12 offset1 open_time_area" style="display:none">
                                    <label class="span1 checkbox inline">
                                        时间:
                                    </label>
                                    <label class="span11 checkbox inline">
                                        <div class="row">
                                            <input type="text" id="inlineCheckbox1" name="open_time_start1" class="js-time" placeholder="开始时间" value="{$card_detail['open_time_period'][0]['start']}">~
                                            <input type="text" id="inlineCheckbox1" name="open_time_end1" class="js-time" placeholder="结束日期" value="{$card_detail['open_time_period'][0]['end']}">
                                        </div>
                                        <div class="row" style="margin-top: 2px;">
                                            <input type="text" id="inlineCheckbox1" name="open_time_start2" class="js-time" placeholder="开始时间" value="{$card_detail['open_time_period'][1]['start']}">~
                                            <input type="text" id="inlineCheckbox1" name="open_time_end2" class="js-time"  placeholder="结束日期" value="{$card_detail['open_time_period'][1]['end']}">
                                        </div>
                                    </label>
                                    <span class="offset1 inline">时间区间可以填写一个也可以填写两个</span>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr class='card_detail'>
                        <th>使用须知<br>(选填)</th>
                        <td>
                            <script type="text/plain" id="content" name="user_notice">{$card_detail.user_notice}</script>
                        </td>
                    </tr>
                </table>
            </div>

    		<div class="span3">
                <table width="100%"  cellpadding="2" cellspacing="2" class="table table-bordered card_detail">
                    <tr><td><b>导入卡券</b></td></tr>
                    <tr><td><input type="file" name="code_file"   accept="text/csv" style="width: 100%;"/></td></tr>
                </table>
				<table width="100%"  cellpadding="2" cellspacing="2" class="table table-bordered">
						<tr><td><b>活动图片</b><if condition="$card['card_icon']"><a href="{:U('Materials/del_img',array('id'=>$card['id'],'type'=>'card_icon'))}" style="float: right;">删除图片</a></if></td></tr>
						<if condition="$card['card_icon']">
							<tr><td>
								<img src="{$urlimg}{$card.card_icon}" name="card_icon">
								<input type="hidden" name="card_icon" value="{$card.card_icon}" />
							</td></tr>
			        	</if>
						<tr><td><input type="file" name="newcard_icon" id="imgfile" accept="image/*" style="width: 100%;"/></td></tr>
						<tr><td><img src="" id="img"></td></tr>
				</table>
            </div>
        </div>
        <div class="form-actions">
            <button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
            <a class="btn" href="{:U('Materials/index')}">返回</a>
        </div>
    </form>
</div>

<!-- Dialog -->
<div id="dialog_areas" class="dialog-areas"style="display:none">
    <div class="ks-contentbox">
        <div class="ks-stdmod-header">
            <div class="title">选择区域</div>
        </div>
        <div class="ks-stdmod-body">
            <form method="post">
                <ul id="J_CityList">
                    <!-- BEGIN CITY LIST ----->
                    <li>
                        <div class=" dcity clearfix">
                            <foreach name="regions" item="volist" key="key" >
                                <div class="ecity gcity">
                                <span class="group-label">
                                <input type="checkbox" id="J_Group_1" class="J_Group" value="{$volist['code']}"/>
                                <!--<label for="J_Group_1">{$volist['name']}</label>-->
                                    <label for="J_Group_1">全国</label>
                                </span>
                                </div>
                                <div class="province-list">
                                <foreach name="volist['lower']" item="vo" key="k" >
                                    <div class="ecity">
                                        <span class="gareas">
                                            <input type="checkbox" class="J_Province" id="J_Province_{$vo.id}" value="{$vo['code']}"/>
                                            <label for="J_Province_{$vo.id}">{$vo['shortname']}</label>
                                            <span class="check_num"/></span>
                                            <em class="zt trigger"></em>
                                            <div class="citys">
                                                <foreach name="vo['lower']" item="v" key="k" >
                                                    <span class="areas">
                                                    <input type="checkbox" class="J_City" id="J_City_{$v.id}" value="{$v['code']}"/>
                                                    <label for="J_City_{$v.id}">{$v['name']}</label>
                                                    </span>
                                                </foreach>
                                                <p style="text-align: right;">
                                                    <input type="button" class="close_button" value="关闭"/>
                                                </p>
                                            </div>
                                        </span>
                                    </div>
                                </foreach>
                                </div>
                            </foreach>
                        </div>
                    </li>
                    <!--END------>
                </ul>
                <div class="btns">
                    <button class="J_Submit" type="button">确定</button>
                    <button class="J_Cancel" type="button">取消</button>
                </div>
            </form>
        </div>
        <div class="ks-stdmod-footer">
            <a class="ks-ext-close" href="javascript:void(0)">
                <span class="ks-ext-close-x">X</span>
            </a>
        </div>
    </div>
</div>
<script src="//cdn.bootcss.com/jquery-validate/1.15.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/M97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/js/transport.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.DIMAUB;
    window.onload=function(){
        //编辑器
        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }
        //增加编辑器验证规则
        jQuery.validator.addMethod('editorcontent', function() {
            try {
                editorcontent.sync();
            } catch (err) {
            }
            return editorcontent.hasContents();
        });
        var area=document.getElementsByName("area");
        var areasbox=document.getElementById("areasbox");
        for(var i=0;i<area.length;i++){
            area[i].onclick=function(){
                var k=0;
                for(var n=0;n<area.length;n++){
                    if(area[n].checked){
                        k++;
                    }
                }
                if(k==0){
                    areasbox.style.display="none";
                }else{
                    areasbox.style.display="block";
                }
            }
        }
        var group=document.getElementsByName("group");
        var groupbox=document.getElementById("groupbox");
        for(var i=0;i<group.length;i++){
            group[i].onclick=function(){
                var k=0;
                for(var n=0;n<group.length;n++){
                    if(group[n].checked){
                        k++;
                    }
                }
                if(k==0){
                    groupbox.style.display="none";
                }else{
                    groupbox.style.display="block";
                }
            }
        }
    }
    $("#imgfile").change(function () {
        var objUrl = getObjectURL(this.files[0]);
        console.log("objUrl = " + objUrl);
        if (objUrl) {
            $("#img").attr("src", objUrl);
        }
    });
    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }

    /*
     * 物料类型切换函数
     */
    $(function(){
        card_type = "{$card['card_type']}";
        switch (card_type) {
            case '1': //物料类型为红包
                console.log(this.value);
                $("#redinput").css('display', '');
                $(".card_detail").css('display', 'none');
                $("#card_count_th").html('红包总额/分');
                break;
            case '2': //物料类型为核销
                console.log(this.value);
                $("#redinput").css('display', 'none');
                $(".card_detail").css('display', '');
                break;
            case '5': //物料类型为实物
                console.log(this.value);
                $("#redinput").css('display', 'none');
                $(".card_detail").css('display', '');
                break;
            default:
                $("#redinput").css('display', 'none');
                $(".card_detail").css('display', 'none');
                $("#card_count_th").html('卡券总量/个');
        }
        open_time_type = "{$card_detail['open_time_type']}";
        switch (open_time_type) {
            case '1': //全部时段
                $(".open_time_area").css('display', 'none');
                break;
            case '2': //部分时段
                $(".open_time_area").css('display', '');
                break;
        }
    });
    /*
     * 卡券兑换时间类型
     */
    $("input[name='open_time_type']").change(function () {
        switch (this.value) {
            case '1': //全部时段
                console.log(this.value);
                $(".open_time_area").css('display', 'none');
                break;
            case '2': //部分时段
                console.log(this.value);
                $(".open_time_area").css('display', '');
                break;
        }
    });
</script>
</body>
</html>
